package org.summer.gateway.config;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.util.pattern.PathPatternParser;
import org.summer.gateway.jwt.JsonWebTokenProperties;
import org.summer.gateway.security.SecurityProperties;

@Log4j2
@Configuration
@EnableConfigurationProperties
@RequiredArgsConstructor
public class GatewayConfig {
    private final JsonWebTokenProperties webTokenProperties;
    private final SecurityProperties securityProperties;

    @Value("${spring.r2dbc.url}")
    private String dbUrl;
    @Value("${spring.r2dbc.username}")
    private String dbUsername;
    @Value("${spring.data.redis.host}")
    private String redisHost;

    @PostConstruct
    void inti(){
        log.debug("mysql数据库连接地址: {}", dbUrl);
        log.debug("mysql数据库连接用户给: {}", dbUsername);
        log.debug("redis数据库地址: {}", redisHost);
        log.debug("jwt配置属性: {}", webTokenProperties);
        log.debug("security配置属性: {}", securityProperties);
    }

    /**
     * 路径匹配器
     */
    @Bean
    public PathPatternParser pathPatternParser(){
        return PathPatternParser.defaultInstance;
    }

}
